home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Control Common / CEnumConnectionPoints.cpp < prev    next >
Text File  |  1996-10-17  |  3KB  |  166 lines

  1. //
  2. #include "ocheaders.h"
  3. #include <LArray.h>
  4. #include "CEnumConnectionPoints.h"
  5.  
  6.  
  7. //
  8. //  CEnumConnectionPoints::CEnumConnectionPoints
  9. //
  10.  
  11. CEnumConnectionPoints::CEnumConnectionPoints(LArray* ConnectionPoints)
  12. {
  13.     unsigned long         i;
  14.     IConnectionPoint*    cp;
  15.     
  16.     m_RefCount = 0;
  17.     m_Current = 1;
  18.     
  19.     // Create the enumerator's connection points array
  20.     m_ConnectionPoints = new LArray(sizeof(IConnectionPoint*));
  21.     
  22.     // Copy all the connection point pointers into our local array
  23.     for ( i = 1; i <= ConnectionPoints->GetCount(); i ++ )
  24.     {
  25.         ConnectionPoints->FetchItemAt(i, &cp);
  26.         m_ConnectionPoints->InsertItemsAt(1, i, &cp);
  27.         cp->AddRef();
  28.     }
  29. }
  30.  
  31.  
  32. //
  33. //  CEnumConnectionPoints::~CEnumConnectionPoints
  34. //
  35.  
  36. CEnumConnectionPoints::~CEnumConnectionPoints(void)
  37. {
  38.     unsigned long         i;
  39.     IConnectionPoint*    cp;
  40.     
  41.     // Release all the connection points we have
  42.     for ( i = 1; i <= m_ConnectionPoints->GetCount(); i ++ )
  43.     {
  44.         m_ConnectionPoints->FetchItemAt(i, &cp);
  45.         cp->Release();
  46.     }
  47.     
  48.     delete m_ConnectionPoints;
  49. }
  50.  
  51.  
  52. //
  53. //  CEnumConnectionPoints::IUnknown::QueryInterface
  54. //
  55. //  Returns a pointer to the specified interface on a component to which a
  56. //  client currently holds an interface pointer.
  57. //
  58. STDMETHODIMP
  59. CEnumConnectionPoints::QueryInterface(REFIID RefID, void** Obj)
  60. {
  61.     void* pv;
  62.  
  63.     if (RefID == IID_IUnknown)
  64.         pv = (void*) this;
  65.     else if (RefID == IID_IEnumConnectionPoints )
  66.         pv = (void*)(IEnumConnectionPoints*) this;
  67.     else {
  68.         *Obj = NULL;
  69.         return ResultFromScode(E_NOINTERFACE);
  70.     }
  71.  
  72.     *Obj = pv;
  73.     ((IUnknown*) pv)->AddRef();
  74.     return ResultFromScode(S_OK);
  75. }
  76.  
  77.  
  78. //
  79. //  CEnumConnectionPoints::IUnknown::AddRef
  80. //
  81. //  Increments the reference count for the calling interface.
  82. //
  83. STDMETHODIMP_(ULONG)
  84. CEnumConnectionPoints::AddRef(void)
  85. {
  86.     return ++m_RefCount;
  87. }
  88.  
  89.  
  90. //
  91. //  CEnumConnectionPoints::IUnknown::Release
  92. //
  93. //  Decrements the reference count for the calling interface on a object.  If
  94. //  the reference count on the object falls to zero, the object is freed.
  95. //
  96. STDMETHODIMP_(ULONG)
  97. CEnumConnectionPoints::Release(void)
  98. {
  99.     if (--m_RefCount != 0)
  100.         return m_RefCount;
  101.  
  102.     delete this;
  103.     return 0;
  104. }
  105.  
  106.  
  107. //
  108. //  CEnumConnectionPoints::IEnumConnectionPoints::Next
  109. //
  110. STDMETHODIMP
  111. CEnumConnectionPoints::Next(unsigned long NumRequested, 
  112.                 IConnectionPoint** ConnectionPoint,
  113.                 unsigned long* NumReturned)
  114. {
  115.     unsigned long     Returned = 0;
  116.     unsigned long    RemainingRequests = NumRequested;
  117.     
  118.     while ( m_Current <= m_ConnectionPoints->GetCount() && RemainingRequests > 0 )
  119.     {
  120.         m_ConnectionPoints->FetchItemAt(m_Current, ConnectionPoint);
  121.         (*ConnectionPoint)->AddRef();
  122.         
  123.         // Move to next connection point
  124.         ConnectionPoint++;
  125.         
  126.         // One more returned, one less requested
  127.         Returned ++;
  128.         RemainingRequests --;
  129.         
  130.         // Next item please
  131.         m_Current++;
  132.     }
  133.     
  134.     // if the client is interested, pass this info back
  135.     if ( NumReturned )
  136.         (*NumReturned) = Returned;
  137.         
  138.     // Set the correct return value
  139.     if ( Returned == NumRequested )
  140.         return ResultFromScode(S_OK);
  141.     else
  142.         return ResultFromScode(S_FALSE);
  143. }
  144.  
  145.  
  146. //
  147. //  CEnumConnectionPoints::IEnumConnectionPoints::Skip
  148. //
  149. STDMETHODIMP
  150. CEnumConnectionPoints::Skip(unsigned long cConnections)
  151. {
  152. #pragma unused (cConnections)
  153.     return E_NOTIMPL;
  154. }
  155.  
  156.  
  157. //
  158. //  CEnumConnectionPoints::IEnumConnectionPoints::Clone
  159. //
  160. STDMETHODIMP
  161. CEnumConnectionPoints::Clone(IEnumConnectionPoints** Enum)
  162. {
  163. #pragma unused (Enum)
  164.     return E_NOTIMPL;
  165. }
  166.